package com.lixh.sdk.base.util

import android.content.Context
import android.view.Gravity
import android.widget.Toast
import androidx.annotation.StringRes

fun Context.toast(
    content: String,
    duration: Int = Toast.LENGTH_SHORT,
    gravity: Int = Gravity.BOTTOM,
    xOffset: Int = 0,
    yOffset: Int = 0,
) {
    val toast = Toast.makeText(this, content, duration)
    if (gravity != Gravity.BOTTOM) toast.setGravity(gravity, xOffset, yOffset)
    toast.show()

}

fun Context.toast(
    @StringRes id: Int,
    duration: Int = Toast.LENGTH_SHORT,
    gravity: Int = Gravity.BOTTOM,
    xOffset: Int = 0,
    yOffset: Int = 0,
) {
    toast(getString(id), duration, gravity, xOffset, yOffset)
}


fun String.toast(
    duration: Int = Toast.LENGTH_SHORT, gravity: Int = Gravity.BOTTOM, xOffset: Int = 0,
    yOffset: Int = 0,
) {
    application.toast(this, duration, gravity, xOffset, yOffset)
}

fun Int.toast(
    duration: Int = Toast.LENGTH_SHORT, gravity: Int = Gravity.BOTTOM, xOffset: Int = 0,
    yOffset: Int = 0,
) {
    application.toast(this, duration, gravity, xOffset, yOffset)
}